#
# Copyright (C) 2013 Will Dignazio
#
ROOTDIR = $(PWD)
PREFIX	= $ROOTDIR

CC	= clang
CFLAGS	= -O0 -g -Wall -Werror -I $(ROOTDIR)/include/
LIBS	= -lcurl -lpthread

ULIBS	= 
CSRC	= request.c	\
	  session.c	\
	  handshake.c	\
	  work.c	\
	  queue.c	\
	  socketio.c	\

HEADERS	= internal.h	\
	  include/*.h	\

COBJ	= $(CSRC:.c=.o)
CLIBS	= $(ULIBS:=.a)

export ROOTDIR
export CFLAGS
export CC

.PHONY: all clean util

all: libsocketio.a util

libsocketio.a: $(CSRC) $(HEADERS) $(COBJ)
	ar rcs libsocketio.a $(COBJ) $(CLIBS)

%.o: %.c internal.h
	$(CC) $(CFLAGS) -c -o $@ $<

%.a:
	export LOCALDIR=$(ROOTDIR)/$*
	$(MAKE) $(MAKEFLAGS) -C $*
	cp $*/$@ ./

util:
	$(MAKE) $(MAKEFLAGS) -C $(ROOTDIR)/util

clean:
	@for lib in $(ULIBS); do	\
		$(MAKE) -C $$lib clean;	\
	done
	rm -f *.a
	rm -f *.o
